home *** CD-ROM | disk | FTP | other *** search
/ El Mac 9 / El Mac 9.iso / Shareware / Demos / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Waves / Compare Waves next >
Encoding:
Text File  |  1996-01-29  |  7.5 KB  |  329 lines  |  [TEXT/IGR0]

  1. | The purpose of these functions is to compare two waves to see if they are identical.
  2. | The main function is CompareWaves(), at the bottom of the file.
  3.  
  4. | NOTE: *** This procedure file requires Igor Pro 3.0 or later. ***
  5.  
  6. #pragma rtGlobals=1
  7.  
  8. Function CompareWavesTypes(w1, w2, printDiscrepancy)
  9.     Wave w1
  10.     Wave w2
  11.     Variable printDiscrepancy        | non-zero to print message about discrepancy
  12.  
  13.     Variable type1, type2
  14.     
  15.     type1 = WaveType(w1)
  16.     type2 = WaveType(w2)
  17.     if (type1 != type2)
  18.         if (printDiscrepancy)
  19.             Printf "*** Discrepancy: First wave type is %d, second is %d.\r", type1, type2
  20.         endif
  21.         return 1
  22.     endif
  23.     
  24.     return 0
  25. End
  26.  
  27. Function CompareWavesNumDimensions(w1, w2, printDiscrepancy)
  28.     Wave w1
  29.     Wave w2
  30.     Variable printDiscrepancy        | non-zero to print message about discrepancy
  31.     
  32.     Variable w1Dims, w2Dims
  33.     
  34.     w1Dims = WaveDims(w1)
  35.     w2Dims = WaveDims(w2)
  36.     if (w1Dims != w2Dims)
  37.         if (printDiscrepancy)
  38.             Printf "*** Discrepancy: First has %d dimensions, second has %d dimensions.\r", w1Dims, w2Dims
  39.         endif
  40.         return 1
  41.     endif
  42.     return 0
  43. End
  44.  
  45. Function CompareWavesDimSizes(w1, w2, printDiscrepancy)
  46.     Wave w1
  47.     Wave w2
  48.     Variable printDiscrepancy        | non-zero to print message about discrepancy
  49.     
  50.     Variable n1, n2
  51.     
  52.     n1 = DimSize(w1, 0)
  53.     n2 = DimSize(w2, 0)
  54.     if (n1 != n2)
  55.         if (printDiscrepancy)
  56.             Printf "*** Discrepancy: First has %d rows, second has %d rows.\r", n1, n2
  57.         endif
  58.         return 1
  59.     endif
  60.     
  61.     n1 = DimSize(w1, 1)
  62.     n2 = DimSize(w2, 1)
  63.     if (n1 != n2)
  64.         if (printDiscrepancy)
  65.             Printf "*** Discrepancy: First has %d columns, second has %d columns.\r", n1, n2
  66.         endif
  67.         return 1
  68.     endif
  69.     
  70.     n1 = DimSize(w1, 2)
  71.     n2 = DimSize(w2, 2)
  72.     if (n1 != n2)
  73.         if (printDiscrepancy)
  74.             Printf "*** Discrepancy: First has %d layers, second has %d layers.\r", n1, n2
  75.         endif
  76.         return 1
  77.     endif
  78.     
  79.     n1 = DimSize(w1, 3)
  80.     n2 = DimSize(w2, 3)
  81.     if (n1 != n2)
  82.         if (printDiscrepancy)
  83.             Printf "*** Discrepancy: First has %d chunks, second has %d chunks.\r", n1, n2
  84.         endif
  85.         return 1
  86.     endif
  87.     
  88.     return 0
  89. End
  90.  
  91. Function CompareWavesValues(w1, w2, printDiscrepancy)
  92.     Wave w1
  93.     Wave w2
  94.     Variable printDiscrepancy        | non-zero to print message about discrepancy
  95.     
  96.     Variable isText
  97.     Variable p, q, r, s
  98.     Variable numRows, numColumns, numLayers, numChunks
  99.     Variable discrepancy
  100.     
  101.     isText = WaveType(w1) == 0
  102.     
  103.     numRows = DimSize(w1, 0)
  104.     numColumns = DimSize(w1, 1)
  105.     numLayers = DimSize(w1, 2)
  106.     numChunks = DimSize(w1, 3)
  107.     
  108.     s = 0
  109.     do
  110.         r = 0
  111.         do
  112.             q = 0
  113.             do
  114.                 p = 0
  115.                 do
  116.                     if (numRows==0)
  117.                         break
  118.                     endif
  119.                     if (isText)
  120.                         Wave/T tw1=w1, tw2=w2        | so compiler knows they are text waves
  121.                         discrepancy = CmpStr(tw1[p][q][r][s], tw2[p][q][r][s]) != 0
  122.                     else
  123.                         discrepancy = w1[p][q][r][s] != w2[p][q][r][s]
  124.                     endif
  125.                     if (discrepancy)
  126.                         if (printDiscrepancy)
  127.                             Printf "*** Discrepancy in value: Row=%d, column=%d, layer=%d, chunk=%d.\r", p, q, r, s
  128.                         endif
  129.                         return 1
  130.                     endif
  131.                     p += 1
  132.                 while (p < numRows)
  133.                 q += 1
  134.             while (q < numColumns)
  135.             r += 1
  136.         while (r < numLayers)
  137.         s += 1
  138.     while (s < numChunks)
  139.     
  140.     return 0
  141. End
  142.  
  143. Function CompareWavesScaling(w1, w2, printDiscrepancy)
  144.     Wave w1
  145.     Wave w2
  146.     Variable printDiscrepancy        | non-zero to print message about discrepancy
  147.     
  148.     Variable dimension
  149.     Variable/D v1, v2
  150.     
  151.     dimension = 0
  152.     do
  153.         v1 = DimOffset(w1, dimension)
  154.         v2 = DimOffset(w2, dimension)
  155.         if (v1 != v2)
  156.             if (printDiscrepancy)
  157.                 Printf "*** Discrepancy: Different scale offset in dimension %d, first=%g, second=%g.\r", dimension, v1, v2
  158.             endif
  159.             return 1
  160.         endif
  161.         
  162.         v1 = DimDelta(w1, dimension)
  163.         v2 = DimDelta(w2, dimension)
  164.         if (v1 != v2)
  165.             if (printDiscrepancy)
  166.                 Printf "*** Discrepancy: Different scale delta in dimension %d, first=%g, second=%g.\r", dimension, v1, v2
  167.             endif
  168.             return 1
  169.         endif
  170.         
  171.         dimension += 1
  172.     while (dimension < WaveDims(w1))
  173.     
  174.     return 0
  175. End
  176.  
  177. Function CompareWavesUnits(w1, w2, printDiscrepancy)
  178.     Wave w1
  179.     Wave w2
  180.     Variable printDiscrepancy        | non-zero to print message about discrepancy
  181.     
  182.     Variable dimension
  183.     String units1, units2
  184.     
  185.     dimension = 0
  186.     do
  187.         units1 = WaveUnits(w1, dimension)
  188.         units2 = WaveUnits(w2, dimension)
  189.         if (CmpStr(units1, units2) != 0)
  190.             if (printDiscrepancy)
  191.                 Printf "*** Discrepancy: Different units in dimension %d, first=\"%s\", second=\"%s\".\r", dimension, units1, units2
  192.             endif
  193.             return 1
  194.         endif
  195.         dimension += 1
  196.     while (dimension < WaveDims(w1))
  197.     
  198.     return 0
  199. End
  200.  
  201. Function CompareWavesNotes(w1, w2, printDiscrepancy)
  202.     Wave w1
  203.     Wave w2
  204.     Variable printDiscrepancy        | non-zero to print message about discrepancy
  205.     
  206.     String note1, note2
  207.     
  208.     note1 = Note(w1)
  209.     note2 = Note(w2)
  210.     if (CmpStr(note1, note2) != 0)
  211.         if (printDiscrepancy)
  212.             Printf "*** Discrepancy: Different wave notes.\r", note1, note2
  213.         endif
  214.         return 1
  215.     endif
  216.     
  217.     return 0
  218. End
  219.  
  220. Function CompareWavesLabels(w1, w2, printDiscrepancy)
  221.     Wave w1
  222.     Wave w2
  223.     Variable printDiscrepancy        | non-zero to print message about discrepancy
  224.     
  225.     Variable element, numElements
  226.     Variable dimension
  227.     String label1, label2
  228.     
  229.     dimension = 0
  230.     do
  231.         numElements = DimSize(w1, dimension)
  232.         element = -1                    // element -1 is the label for the entire dimension
  233.         do
  234.             if (numElements == 0)
  235.                 break
  236.             endif
  237.             label1 = GetDimLabel(w1, dimension, element)
  238.             label2 = GetDimLabel(w2, dimension, element)
  239.             if (CmpStr(label1, label2) != 0)
  240.                 if (printDiscrepancy)
  241.                     Printf "*** Discrepancy: Different labels. Dimension %d, element %d. First is '%s', second is '%s'.\r", dimension, element, label1, label2
  242.                 endif
  243.                 return 1
  244.             endif
  245.             element += 1
  246.         while (element < numElements)
  247.         dimension += 1
  248.     while (dimension < WaveDims(w1))
  249.     
  250.     return 0
  251. End
  252.  
  253. | CompareWaves(w1, w2, testMask, printDispcrepancy)
  254. |    Compares properties of the waves, returning 0 if the waves are equal and non-zero
  255. |    if there is a discrepancy.
  256. |    testMask determines which tests are done (details below).
  257. |    If printDiscrepancy is non-zero and if there is a discrepancy, CompareWaves prints
  258. |    a discrepancy message in the history area.
  259. |    CompareWaves compares the following properties:
  260. |        Test 1:    Wave types (e.g. single precision, double precision, text)
  261. |        Test 2:    The number of dimensions.
  262. |        Test 3:    The size of each dimension.
  263. |        Test 4:    The dimension labels for each dimensions.
  264. |        Test 5:    The scaling of each dimension.
  265. |        Test 6:    The units for each dimension.
  266. |        Test 7:    The wave notes.
  267. |        Test 8:    The value of each data point.
  268. |
  269. |    To execute all tests, or until a discrepancy is found, pass -1 for testMask.
  270. |    To execute a subset of the test, set the corresponding bit in testMask.
  271. |    For example, to do tests 1, 2, 3 and 8:
  272. |        testMask = 2^1 + 2^2 + 2^3 + 2^8
  273. Function CompareWaves(w1, w2, testMask, printDiscrepancy)
  274.     Wave w1
  275.     Wave w2
  276.     Variable testMask                | Set bit 2^i to do test number i.
  277.     Variable printDiscrepancy        | Non-zero to print message about discrepancy.
  278.     
  279.     if (testMask %& 2^1)
  280.         if (CompareWavesTypes(w1, w2, printDiscrepancy))
  281.             return 1
  282.         endif
  283.     endif
  284.     
  285.     if (testMask %& 2^2)
  286.         if (CompareWavesNumDimensions(w1, w2, printDiscrepancy))
  287.             return 2
  288.         endif
  289.     endif
  290.         
  291.     if (testMask %& 2^3)
  292.         if (CompareWavesDimSizes(w1, w2, printDiscrepancy))
  293.             return 3
  294.         endif
  295.     endif
  296.         
  297.     if (testMask %& 2^4)
  298.         if (CompareWavesLabels(w1, w2, printDiscrepancy))
  299.             return 4
  300.         endif
  301.     endif
  302.         
  303.     if (testMask %& 2^5)
  304.         if (CompareWavesScaling(w1, w2, printDiscrepancy))
  305.             return 5
  306.         endif
  307.     endif
  308.         
  309.     if (testMask %& 2^6)
  310.         if (CompareWavesUnits(w1, w2, printDiscrepancy))
  311.             return 6
  312.         endif
  313.     endif
  314.         
  315.     if (testMask %& 2^7)
  316.         if (CompareWavesNotes(w1, w2, printDiscrepancy))
  317.             return 7
  318.         endif
  319.     endif
  320.         
  321.     if (testMask %& 2^8)
  322.         if (CompareWavesValues(w1, w2, printDiscrepancy))
  323.             return 8
  324.         endif
  325.     endif
  326.     
  327.     return 0
  328. End
  329.